<?php
require_once ("../../src/db/connectdatabase.php");
require_once ("../../src/entitys/Bank.php");

function getBanks($isuse) {
	$con = new ConnectDB();
	
	$tbl = "banks";
	$fn = array('bankid', 'bankname', 'banklogo', 'datecreate');
	$condetion = array('isuse' => $isuse);
	return $con -> getvalueorderby($tbl, $fn, $condetion, 'datecreate');
}

function getBank($idbank) {
	$con = new ConnectDB();
	
	$tbl = "banks";
	$fn = array('bankid', 'bankname', 'banklogo', 'datecreate');
	$condetion = array('bankid' => $idbank);
	return $con -> getvalue($tbl, $fn, $condetion);
}

function insertBank($bank) {
	$con = new ConnectDB();
	
	$tbl = "banks";
	$fn = array('bankid' => ($bank -> getID()), 'bankname' => ($bank -> getName()), 'banklogo' => ($bank -> getLogo()), 'datecreate' => ($bank -> getDatecreate()));
	return $con -> insert($tbl, $fn);
}

function updateBank($bank) {
	$con = new ConnectDB();
	
	$tbl = "banks";
	$fn = array('bankname' => ($bank -> getName()), 'banklogo' => ($bank -> getLogo()), 'datecreate' => ($bank -> getDatecreate()));
	$condition = array('bankid' => ($bank -> getID()));
	return $con -> update($tbl, $fn, $condition);
}

function restoreBank($idbank) {
	$con = new ConnectDB();
	
	$tbl = "banks";
	$fn = array('isuse' => true, 'datecreate' => time());
	$condition = array('bankid' => $idbank);
	return $con -> update($tbl, $fn, $condition);
}

function deleteBank($idbank) {
	$con = new ConnectDB();
	
	$tbl = "banks";
	$fn = array('isuse' => false);
	$condition = array('bankid' => $idbank);
	return $con -> update($tbl, $fn, $condition);
}

function updatetableorther($tbl, $bank) {
	$con = new ConnectDB();
	
	$fn = array('bankname' => ($bank -> getName()), 'banklogo' => ($bank -> getLogo()));
	$condition = array('bankid' => ($bank -> getID()));
	return $con -> update($tbl, $fn, $condition);
}

?>